package com.xyd.Servlet;

import com.xyd.Biz.CommonTableBiz;
import com.xyd.Biz.Impl.CommonTableBizImpl;
import com.xyd.Biz.Impl.ProductClassBizImpl;
import com.xyd.Biz.ProductClassBiz;
import com.xyd.Entity.Commodity;
import com.xyd.Entity.CommonTable;
import com.xyd.Util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/html/manage/RemoveProductClassServlet")
public class RemoveProductClassServlet extends HttpServlet {


    SqlSession session = null;

    public void init() {
        session = SqlSessionFactoryUtil.open();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CommonTableBiz commonTableBiz = new CommonTableBizImpl();
        String id = request.getParameter("id");
        CommonTable commonTable = commonTableBiz.getCommonTableById(Integer.parseInt(id));
        int result = commonTableBiz.delCommonTableById(commonTable);
        if (result > 0) {
            request.getRequestDispatcher("ProductClassServlet").forward(request, response);
        } else {

        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    /* ProductClassBiz productClassBiz = new ProductClassBizImpl();
    SqlSession session = null;

    public void init() {
        session = SqlSessionFactoryUtil.open();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String commodityId = request.getParameter("id");
        Commodity commodity = productClassBiz.getCommodityById(Integer.valueOf(commodityId));
        int result = productClassBiz.removeProductClassById(commodity);
        if (result>0){
            session.commit();
            request.getRequestDispatcher("ProductClassServlet").forward(request, response);
        } else {

        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }*/
}
